package org.han.permission.service.impl;

import org.han.base.service.impl.BaseServiceImpl;
import org.han.permission.domain.Role;
import org.han.permission.dto.RolePermissionDTO;
import org.han.permission.mapper.RoleMapper;
import org.han.permission.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    @Resource
    private RoleMapper mapper;

    @Transactional
    @Override
    public void saveRolePermission(RolePermissionDTO dto) {
        // 删除角色所有权限
        mapper.deletePermissionByRoleId(dto.getRoleId());
        // 新增权限
        mapper.batchSaveRolePermission(dto.getRoleId(), dto.getPermissionSns());
    }

    @Override
    public List<String> getRolePermissionSns(Long roleId) {
        // 查询角色权限
        return mapper.getRolePermissionSns(roleId);
    }
}
